#!/usr/bin/perl
if(@ARGV < 2)
{
	die "Not enough arguments, please input the basefile and EDitScript\n";
}
open BASE_IN_EDS, $ARGV[0];
while(<BASE_IN_EDS>){
	s/\r\n/\n/g;
	s/\r/\n/g;
	$BaseStr .= $_;
}
@baseSeq = split //, $BaseStr;
@ops=split /:/, $ARGV[1];
$Iterator = 0;
foreach $op (@ops){
	@segments = split /,/, $op;
	$type = $segments[0];
	$pos = $segments[1];
	$char = pack("c",$segments[2]);
	while($Iterator < $pos){
		print $baseSeq[$Iterator++];
	}
	if($type eq "ins")
	{
		print "\033[0m\033[1;31m$char\033[0m";
		@baseSeq = (@baseSeq[0 .. $pos-1],$char,@baseSeq[$pos .. $#baseSeq]);
		$Iterator++;
	}
	if($type eq "del"){
		print "\033[0m\033[5m\033[4m$char\033[0m";
		@baseSeq = (@baseSeq[0 .. $pos-1],@baseSeq[$pos+1 ..$#baseSeq]);
	}
}
while($Iterator <= $#baseSeq){
	print $baseSeq[$Iterator++];
}
